<template>
	<view :class="['page',{'iphoneX':isIphoneX}]">
		<template v-if="type==1">
			<view class="h90">
				<view class="fix-wrap">
					<view class="h45 search-area">
						<view class="search-form">
							<view class="icon iconfont f-s44">&#xe622;</view>
							<input type="text" confirm-type="search" v-model="form.keyword" class="sc-inp" @confirm="search">
							<view v-if="form.keyword" class="clear-btn iconfont f-s44" @click="clearKeyword">&#xe724;</view>
						</view>  	
					</view>
					<view class="h45 limit-tab">
						<view class="item" :class="{'active':form.apply_status==1}" @click="changeStatus(1)">
							<view class="name">待审批</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==2}" @click="changeStatus(2)">
							<view class="name">已审批</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==3}" @click="changeStatus(3)">
							<view class="name">不通过</view>
							<view class="active-line"></view>
						</view>
					</view>
					
				</view>
			</view>
			<view class="body">
				<template v-if="loadingState.default">
					<c-loading :loadingState="loadingState"></c-loading>
				</template>
				<template v-else>
				<template v-if="list.length>0">
					<view class="list-wrap">
						<view class="item" v-for="(item,index) in list" :key="index" >
							<view class="content">
								<view @click="jump(index)">
									<view class="name row-2">  
										<text v-if="item.apply_type==1">{{item.username}}发的申请入库</text>
										<text v-if="item.apply_type==2">{{item.username}}发的申请出库</text>
										<text v-if="item.apply_type==3">{{item.username}}发的申请需求</text>
										<text v-if="item.apply_type==4">{{item.username}}发的成品入库</text>
										<text v-if="item.apply_type==5">{{item.username}}发的合成成品</text>
										<text v-if="item.apply_type==6">{{item.username}}发的仓库发仓库</text> 
										
										<text v-if="item.apply_status==1" class="f-red">待审批</text>
										<text v-if="item.apply_status==2" class="f-red">审批通过</text>
										<text v-if="item.apply_status==3" class="f-red">审批不通过</text>
										<text v-if="item.apply_status==9" class="f-red">待签收</text>
										<text v-if="item.apply_status==10" class="f-red">已签收</text>
										<text v-if="item.apply_status==4 && (item.apply_type==5 || item.apply_type==4 || item.apply_type==1)" class="f-red">已入库</text>
										<text v-if="item.apply_status==6 && (item.apply_type==5 || item.apply_type==4 || item.apply_type==1||item.apply_type==6)" class="f-red">已入库</text>
										<text v-if="item.apply_status==6 && (item.apply_type==2)" class="f-red">已发货1</text>
										<text v-if="item.apply_status==4 && (item.apply_type==2 || item.apply_type==6)" class="f-red">已发货</text>
										<text v-if="item.apply_status==-1" class="f-red">已撤回</text>
										 
									</view>
									<view v-if="item.product_list.length>0" class="row-2">
										<text>货物名称</text>
										<text v-if="item.product_list.length>1">有{{item.product_list.length}}种货物</text>
										<text v-else>{{item.product_list[0].pname}}</text>
									</view>
									<view class="row-2"> 
										<text>申请时间</text>
										<text>{{item.create_time}}</text>
									</view>
								</view>
								<view class="row-2">
									<text>订单ID:{{item.apply_id}}</text>
									<u-button v-if="item.apply_type==1||item.apply_type==2||item.apply_type==6" text="复制订单" type="success" size="mini" class="copy-btn f-s30" @click="copy(item.apply_type,item.apply_id)"></u-button>  
								</view> 
							</view>
							<view v-if="item.apply_status==1||item.apply_status==2" class="btn-wrap">
								<u-button text="撤回" type="success" size="small" class="btn" @click="recall(item.apply_id)"></u-button> 
							</view>
						</view>
					</view>
					<c-loading :loadingState="loadingState"></c-loading> 
					
				</template> 
				
				<c-empty v-else></c-empty>
				</template>
			</view>
		
		</template>
		
		<template v-if="type==2">
			<view class="h90">
				<view class="fix-wrap">
					<view class="h45 search-area">
						<view class="search-form">
							<view class="icon iconfont f-s44">&#xe622;</view>
							<input type="text" confirm-type="search" v-model="form.keyword" class="sc-inp" @confirm="search">
							<view v-if="form.keyword" class="clear-btn iconfont f-s44" @click="clearKeyword">&#xe724;</view>
						</view>  	
					</view>
					<view class="h45 limit-tab">
						<view class="item" :class="{'active':form.apply_status==1}" @click="changeStatus(1)">
							<view class="name">待审批</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==2}" @click="changeStatus(2)">
							<view class="name">已审批</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==3}" @click="changeStatus(3)">
							<view class="name">不通过</view>
							<view class="active-line"></view>
						</view>
					</view>
				</view>
			</view>
			<view class="body">
				<template v-if="loadingState.default">
					<c-loading :loadingState="loadingState"></c-loading>
				</template>
				<template v-else>
				<template v-if="list.length>0">
					<view class="list-wrap">
						<view class="item" v-for="(item,index) in list" :key="index">
							<view >
								<view class="name row-2" @click="jump(index)">  
									<text v-if="item.apply_type==1">{{item.username}}发的申请入库</text>
									<text v-if="item.apply_type==2">{{item.username}}发的申请出库</text>
									<text v-if="item.apply_type==3">{{item.username}}发的申请需求</text>
									<text v-if="item.apply_type==4">{{item.username}}发的成品入库</text>
									<text v-if="item.apply_type==5">{{item.username}}发的合成成品</text>
									<text v-if="item.apply_type==6">{{item.username}}发的仓库发仓库</text> 
									<text v-if="item.apply_type==7">{{item.username}}发的材料入库</text>
									<text v-if="item.apply_type==8">{{item.username}}发的材料出库</text>
									
									<text v-if="item.apply_status==1" class="f-red">待审批</text>
									<text v-if="item.apply_status==2" class="f-red">审批通过</text>
									<text v-if="item.apply_status==3" class="f-red">审批不通过</text>
									<text v-if="item.apply_status==4 && (item.apply_type==5 || item.apply_type==4 || item.apply_type==1)" class="f-red">已入库</text>
									<text v-if="item.apply_status==6 && (item.apply_type==6)" class="f-red">已入库</text>
									<text v-if="item.apply_status==4 && (item.apply_type==2 || item.apply_type==6)" class="f-red">已发货</text>
									<text v-if="item.apply_status==-1" class="f-red">已撤回</text>
									 
								</view>
								<view v-if="item.product_list.length>0" class="row-2">
									<text>货物名称</text>
									<text v-if="item.product_list.length>1">有{{item.product_list.length}}种货物</text>
									<text v-else>{{item.product_list[0].pname}}</text>
								</view>
								<view class="row-2"> 
									<text>申请时间</text>
									<text>{{item.create_time}}</text>
								</view>
								<view class="row-2">
									<text>订单ID:{{item.apply_id}}</text>
									<view v-if="item.apply_type==1||item.apply_type==2||item.apply_type==6" @click="copy(item.apply_type,item.apply_id)">复制订单</view>
								</view> 
							</view>
							<view  class="btn-wrap">
								<u-button text="详情" type="success" size="small" class="btn" @click="jump(index)" ></u-button>
								<!-- <template v-if="item.apply_status==1">
									<u-button text="同意" type="success" size="small" class="btn"  @click="open(index)"></u-button>
									<u-button text="不同意" type="success" size="small" class="btn m-l2" @click="shenpi(2,index)"></u-button>
								</template> -->
								
							</view>
						</view>
					</view>
					<c-loading :loadingState="loadingState"></c-loading>					
					 
				</template> 
				
				<c-empty v-else></c-empty>
				</template>
			</view>
			<u-popup :show="show" mode="center" @close="close" :closeable="true">
				<view class="storehouse-pupup">
					<u--text text="下级仓库审批人" size="30" bold align="center" class="m-b2"></u--text> 
					<u--form :model="form" ref="uForm" class="form-wrap">
						<u-form-item prop="storehouse_name" borderBottom="true" class="u-form-item m-b2" @click="storehouse.isShow=true">
							<u-input v-model="form.storehouse_name" placeholder="选择下级仓库审批人" disabled disabledColor="#ffffff" border="none" style="pointer-events: none;"/>
							<u-icon	slot="right" name="arrow-right"></u-icon>						
						</u-form-item>
						<!-- <u--text :text="tips" size="30" align="left" color="#ff0000" class="m-b2"></u--text> -->
					</u--form> 
					<u-button type="primary" text="确定" size="small" @click="agree"></u-button>
				</view>
			</u-popup> 
			
			<u-picker :show="storehouse.isShow" :columns="storehouse.data" keyName="val" itemHeight="90" :closeOnClickOverlay="true" @cancel="storehouse.isShow=false" @confirm="changestorehouse" @close="storehouse.isShow=false"></u-picker>
		</template>
		
		<template v-if="type==3">
			<view class="h90">
				<view class="fix-wrap">
					<view class="h45 search-area">
						<view class="search-form">
							<view class="icon iconfont f-s44">&#xe622;</view>
							<input type="text" confirm-type="search" v-model="form.keyword" class="sc-inp" @confirm="search">
							<view v-if="form.keyword" class="clear-btn iconfont f-s44" @click="clearKeyword">&#xe724;</view>
						</view>  	
					</view>
					<view class="h45 limit-tab">
						<view class="item" :class="{'active':form.apply_status==2}" @click="changeStatus(2)">
							<view class="name">待发货</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==4}" @click="changeStatus(4)">
							<view class="name">已发货</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==5}" @click="changeStatus(5)">
							<view class="name">拒绝发货</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==8}" @click="changeStatus(8)">
							<view class="name">拒绝待审批</view>
							<view class="active-line"></view>
						</view>
					</view>
				</view>
			</view>
			<view class="body">
				<template v-if="loadingState.default">
					<c-loading :loadingState="loadingState"></c-loading>
				</template>
				<template v-else>
				<template v-if="list.length>0">
					<view class="list-wrap">
						<view class="item" v-for="(item,index) in list" :key="index" >
							<view class="" @click="sendproduct(index)">
								<view class="name row-2">
									<text v-if="item.apply_type==1">{{item.username}}发的申请入库</text>
									<text v-if="item.apply_type==2">{{item.username}}发的申请出库</text>
									<text v-if="item.apply_type==3">{{item.username}}发的申请需求</text>
									<text v-if="item.apply_type==4">{{item.username}}发的成品入库</text>
									<text v-if="item.apply_type==5">{{item.username}}发的合成成品</text>
									<text v-if="item.apply_type==6">{{item.username}}发的仓库发仓库</text> 
									<!-- {{item.apply_id}} -->
									<!-- <text v-if="item.apply_type==1">入库</text>
									<text v-if="item.apply_type==2">发货</text>
									<text v-if="item.apply_type==4">入库</text>
									<text v-if="item.apply_type==5">入库</text>
									<text v-if="item.apply_type==6 && userInfo.id==item.last_receive_user && item.apply_status==4">入库</text>
									<text v-if="item.apply_type==6 && userInfo.id==item.send_storehouseman && item.apply_status==2">发货</text> -->
									 
								</view>
								<view v-if="item.product_list.length>0" class="row-2">
									<text>货物名称</text>
									<text v-if="item.product_list.length>1">有{{item.product_list.length}}种货物</text>
									<text v-else>{{item.product_list[0].pname}}</text>
								</view>
								<view class="row-2"> 
									<text>申请时间</text>
									<text>{{item.create_time}}</text>
								</view>
								<view class="row-2">
									<text>联系人</text>
									<text>{{item.NAME}}{{item.phone}}</text>
								</view> 
							</view>
							
							<view class="btn-wrap">
								<u-button v-if="item.apply_type==2" text="详情" type="success" size="small" class="btn" @click="sendproduct(index)" ></u-button>
								<u-button v-else text="详情" type="success" size="small" class="btn" @click="jump(index)" ></u-button>
								<u-button v-if="item.ismay != 2 && item.branch_num != 0 && form.apply_status != 8 && (item.apply_status == 2 || item.apply_status == 4 || (form.apply_status == 2 && item.apply_status == 7))" text="拒绝发货" type="warning" size="small" class="btn" @click="jujue(index)"></u-button> 
							</view> 
						</view>
					</view>
					<c-loading :loadingState="loadingState"></c-loading>					
					 
				</template> 
				
				<c-empty v-else></c-empty>
				</template>
			</view>
		
		</template>
		
		<template v-if="type==4">
			<view class="h90">
				<view class="fix-wrap">
					<view class="h45 search-area">
						<view class="search-form">
							<view class="icon iconfont f-s44">&#xe622;</view>
							<input type="text" confirm-type="search" v-model="form.keyword" class="sc-inp" @confirm="search">
							<view v-if="form.keyword" class="clear-btn iconfont f-s44" @click="clearKeyword">&#xe724;</view>
						</view>  	
					</view>
					<view class="h45 limit-tab">
						<view class="item" :class="{'active':form.apply_status==2}" @click="changeStatus(2)">
							<view class="name">待入库</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==4}" @click="changeStatus(4)">
							<view class="name">已入库</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==5}" @click="changeStatus(5)">
							<view class="name">拒绝入库</view>
							<view class="active-line"></view>
						</view>
					</view>
				</view>
			</view>
			<view class="body">
				<template v-if="loadingState.default">
					<c-loading :loadingState="loadingState"></c-loading>
				</template>
				<template v-else>
				<template v-if="list.length>0">
					<view class="list-wrap">
						<view class="item" v-for="(item,index) in list" :key="index">
							<view @click="jump(index)">
								<view class="name row-2">  
									<text v-if="item.apply_type==1">{{item.username}}发的申请入库</text>
									<text v-if="item.apply_type==2">{{item.username}}发的申请出库</text>
									<text v-if="item.apply_type==3">{{item.username}}发的申请需求</text>
									<text v-if="item.apply_type==4">{{item.username}}发的成品入库</text>
									<text v-if="item.apply_type==5">{{item.username}}发的合成成品</text>
									<text v-if="item.apply_type==6">{{item.username}}发的仓库发仓库</text> 
									
									<!-- <text v-if="item.apply_type==1">入库</text>
									<text v-if="item.apply_type==2">发货</text>
									<text v-if="item.apply_type==4">入库</text>
									<text v-if="item.apply_type==5">入库</text>
									<text v-if="item.apply_type==6 && userInfo.id==item.last_receive_user && item.apply_status==4">入库</text>
									<text v-if="item.apply_type==6 && userInfo.id==item.send_storehouseman && item.apply_status==2">发货</text> -->
									 
								</view>
								<view v-if="item.product_list.length>0" class="row-2">
									<text>货物名称</text>
									<text v-if="item.product_list.length>1">有{{item.product_list.length}}种货物</text>
									<text v-else>{{item.product_list[0].pname}}</text>
								</view>
								<view class="row-2"> 
									<text>申请时间</text>
									<text>{{item.create_time}}</text>
								</view>
								<view class="row-2">
									<text>联系人</text>
									<text>{{item.NAME}}{{item.phone}}</text>
								</view> 
							</view>
							<template v-if="userInfo.id==item.last_receive_user && (item.apply_status==2 || item.apply_status==4) "> 
								<view class="btn-wrap">
									<u-button text="入库" type="success" size="small" class="btn"  @click="shenpi(1,index)"></u-button>
									<!-- <u-button text="不同意" type="success" size="small" class="btn m-l2" @click="shenpi(2,index)"></u-button>																	 -->
								</view>
							</template>
						</view>
					</view>
					<c-loading :loadingState="loadingState"></c-loading>
					
					 
				</template> 
				
				<c-empty v-else></c-empty>
				</template>
			</view>
		
		</template>
		
		<template v-if="type==5">
			<view class="h90">
				<view class="fix-wrap">
					<view class="h45 search-area">
						<view class="search-form">
							<view class="icon iconfont f-s44">&#xe622;</view>
							<input type="text" confirm-type="search" v-model="form.keyword" class="sc-inp" @confirm="search">
							<view v-if="form.keyword" class="clear-btn iconfont f-s44" @click="clearKeyword">&#xe724;</view>
						</view>  	
					</view>
					<view class="h45 limit-tab">
						<view class="item" :class="{'active':form.apply_status==1}" @click="changeStatus(1)">
							<view class="name">未结清</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==2}" @click="changeStatus(2)">
							<view class="name">已结清</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==3}" @click="changeStatus(3)">
							<view class="name">部分结清</view>
							<view class="active-line"></view>
						</view>
					</view>
				</view>
			</view>
			<view class="body">
				<template v-if="loadingState.default">
					<c-loading :loadingState="loadingState"></c-loading>
				</template>
				<template v-else>
				<template v-if="list.length>0">
					<view class="list-wrap">
						<view class="item" v-for="(item,index) in list" :key="index">
							<view @click="jump(index,5)">
								<view class="name row-2">  
									<text v-if="item.apply_type==1">{{item.username}}发的申请入库</text>
									<text v-if="item.apply_type==2">{{item.username}}发的申请出库</text>
									<text v-if="item.apply_type==3">{{item.username}}发的申请需求</text> 
									 
									<text v-if="item.project_status==1" class="f-red">未结清</text>
									<text v-if="item.project_status==2" class="f-red">已结清</text>
									<text v-if="item.project_status==3" class="f-red">部分结清</text> 
									 
								</view>
								<view v-if="item.product_list.length>0" class="row-2">
									<text>货物名称</text>
									<text v-if="item.product_list.length>1">有{{item.product_list.length}}种货物</text>
									<text v-else>{{item.product_list[0].pname}}</text>
								</view>
								<view class="row-2"> 
									<text>申请时间</text>
									<text>{{item.create_time}}</text>
								</view>
								<view class="row-2">
									<text>联系人</text>
									<text>{{item.NAME}}{{item.phone}}</text>
								</view> 
							</view>
							<template v-if="item.project_status==1">
								<view class="btn-wrap">
									<u-button text="结清" type="success" size="small" class="btn"  @click="open(index)"></u-button>
									<!-- <u-button text="不同意" type="success" size="small" class="btn m-l2" @click="shenpi(2,index)"></u-button>																	 -->
								</view>
							</template>
						</view>
					</view>
					<c-loading :loadingState="loadingState"></c-loading>
					
					 
				</template> 
				
				<c-empty v-else></c-empty>
				</template>
			</view>
			<u-popup :show="show" mode="center" @close="close" :closeable="true">
				<view class="storehouse-pupup"> 
					<u--text text="结清状态" size="30" bold align="center" class="m-b2"></u--text> 
					<u--form :model="form" ref="uForm" class="form-wrap m-b2">
						<u-form-item label="项目状态" labelWidth="160" prop="project_statusname" borderBottom="true" class="u-form-item" @click="project_status.isShow=true">
							<u-input v-model="form.project_statusname" placeholder="项目状态" disabled disabledColor="#ffffff" border="none" style="pointer-events: none;"/>
							<u-icon	slot="right" name="arrow-right"></u-icon>						
						</u-form-item> 
						<u-form-item label="金额" labelWidth="160" prop="unit" borderBottom="true" class="u-form-item m-b2">
							<u-input type="digit" class="text-inp" v-model="form.payments" border="none" placeholder="结清金额"/> 
							<u--text class="text-unit" text="元" size="30" align="right" ></u--text>
						</u-form-item> 
						<view class="goods-wrap m-b2">
							<view class="hd-title m-b1">
								<u--text class="" text="上传图片" size="30" align="left" ></u--text> 
							</view>	
							<view class="upload-wrap">
								<u-upload
									width="180"
									height="180"
									:fileList="form.fileList1"
									@afterRead="afterRead"
									@delete="deletePic"
									:previewFullImage="true"
									name="1"
									multiple
									:maxCount="10"
								></u-upload>
							</view>
							
						</view>
					</u--form> 
					<u-button type="primary" text="确定" size="small" @click="shenpi(1,currentindex)"></u-button>
				</view>
			</u-popup> 
			
			<u-picker :show="project_status.isShow" :columns="project_status.data" keyName="name" itemHeight="90" :closeOnClickOverlay="true" @cancel="project_status.isShow=false" @confirm="changeprojectstatus" @close="project_status.isShow=false"></u-picker>
		</template>
		
		<template v-if="type==6">
			<view class="h90">
				<view class="fix-wrap">
					<view class="h45 search-area">
						<view class="search-form">
							<view class="icon iconfont f-s44">&#xe622;</view>
							<input type="text" confirm-type="search" v-model="form.keyword" class="sc-inp" @confirm="search">
							<view v-if="form.keyword" class="clear-btn iconfont f-s44" @click="clearKeyword">&#xe724;</view>
						</view>  	
					</view>
					<view class="h45 limit-tab">
						<view class="item" :class="{'active':form.apply_status==1}" @click="changeStatus(1)">
							<view class="name">待审批</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==2}" @click="changeStatus(2)">
							<view class="name">已审批</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==3}" @click="changeStatus(3)">
							<view class="name">不通过</view>
							<view class="active-line"></view>
						</view>
					</view>
				</view>
			</view>
			<view class="body">
				<template v-if="loadingState.default">
					<c-loading :loadingState="loadingState"></c-loading>
				</template>
				<template v-else>
				<template v-if="list.length>0">
					<view class="list-wrap">
						<view class="item" v-for="(item,index) in list" :key="index" @click="jump(index)">
							<view class="name row-2">  
								<text v-if="item.apply_type==1">{{item.username}}发的申请入库</text>
								<text v-if="item.apply_type==2">{{item.username}}发的申请出库</text>
								<text v-if="item.apply_type==3">{{item.username}}发的申请需求</text>
								<text v-if="item.apply_type==4">{{item.username}}发的成品入库</text>
								<text v-if="item.apply_type==5">{{item.username}}发的合成成品</text>
								<text v-if="item.apply_type==6">{{item.username}}发的仓库发仓库</text> 
								     
								<text v-if="item.apply_status==1" class="f-red">待审批</text>
								<text v-if="item.apply_status==2" class="f-red">审批通过</text>
								<text v-if="item.apply_status==3" class="f-red">审批不通过</text>
								<text v-if="item.apply_status==4 && item.apply_type==1" class="f-red">已入库</text> 
								<text v-if="item.apply_status==4 && item.apply_type==2" class="f-red">已发货</text>
								<text v-if="item.apply_status==-1" class="f-red">已撤回</text>
								 
							</view>
							<view v-if="item.product_list.length>0" class="row-2">
								<text>货物名称</text>
								<text v-if="item.product_list.length>1">有{{item.product_list.length}}种货物</text>
								<text v-else>{{item.product_list[0].pname}}</text>
							</view>
							<view class="row-2"> 
								<text>申请时间</text>
								<text>{{item.create_time}}</text>
							</view> 
							<view class="row-2">
								<text>订单ID:{{item.apply_id}}</text>
								<view v-if="item.apply_type==1||item.apply_type==2||item.apply_type==6" @click="copy(item.apply_type,item.apply_id)">复制订单</view>
							</view> 
						</view>
					</view>
					<c-loading :loadingState="loadingState"></c-loading>
					
					 
				</template> 
				
				<c-empty v-else></c-empty>
				</template>
			</view>
		
		</template>
		
		<template v-if="type==7">
			<view class="h90">
				<view class="fix-wrap">
					<view class="h45 search-area">
						<view class="search-form">
							<view class="icon iconfont f-s44">&#xe622;</view>
							<input type="text" confirm-type="search" v-model="form.keyword" class="sc-inp" @confirm="search">
							<view v-if="form.keyword" class="clear-btn iconfont f-s44" @click="clearKeyword">&#xe724;</view>
						</view>  	
					</view>
					<view class="h45 limit-tab">
						<view class="item" :class="{'active':form.apply_status==1}" @click="changeStatus(1)">
							<view class="name">待审批</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==2}" @click="changeStatus(2)">
							<view class="name">已审批</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==3}" @click="changeStatus(3)">
							<view class="name">不通过</view>
							<view class="active-line"></view>
						</view>
					</view>
				</view>
			</view>
			<view class="body">
				<template v-if="loadingState.default">
					<c-loading :loadingState="loadingState"></c-loading>
				</template>
				<template v-else>
				<template v-if="list.length>0">
					<view class="list-wrap">
						<view class="item" v-for="(item,index) in list" :key="index" @click="jump(index,7)">
							<view class="name row-2">  
								<text>{{item.username}}发的入库</text> 
								
								<text v-if="item.apply_status==1" class="f-red">审批中</text>
								<text v-if="item.apply_status==2" class="f-red">审批通过</text>
								<text v-if="item.apply_status==3" class="f-red">审批不通过</text>
								<text v-if="item.apply_status==4 && (item.apply_type==5 || item.apply_type==4 || item.apply_type==1)" class="f-red">已入库</text>
								<text v-if="item.apply_status==6 && (item.apply_type==6)" class="f-red">已入库</text>
								<text v-if="item.apply_status==4 && (item.apply_type==2 || item.apply_type==6)" class="f-red">已发货</text>
								<text v-if="item.apply_status==-1" class="f-red">已撤回</text>
								 
							</view>
							<!-- <view class="row-2">
								<text>货物名称</text>
								<text v-if="item.product_list.length>1">有{{item.product_list.length}}种货物</text>
								<text v-else>{{item.product_list[0].pname}}</text>
							</view>
							<view class="row-2"> 
								<text>申请时间</text>
								<text>{{item.create_time}}</text>
							</view>
							<view class="row-2">
								<text>订单ID</text>
								<text>{{item.apply_id}}</text>
							</view> -->
						</view>
					</view>
					<c-loading :loadingState="loadingState"></c-loading>
					
					 
				</template> 
				
				<c-empty v-else></c-empty>
				</template>
			</view>
		
		</template>
		
		<template v-if="type==8">
			<view class="h90">
				<view class="fix-wrap">
					<view class="h45 search-area">
						<view class="search-form">
							<view class="icon iconfont f-s44">&#xe622;</view>
							<input type="text" confirm-type="search" v-model="form.keyword" class="sc-inp" @confirm="search">
							<view v-if="form.keyword" class="clear-btn iconfont f-s44" @click="clearKeyword">&#xe724;</view>
						</view>  	
					</view>
					<view class="h45 limit-tab">
						<view class="item" :class="{'active':form.apply_status==1}" @click="changeStatus(1)">
							<view class="name">待审批</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==2}" @click="changeStatus(2)">
							<view class="name">已审批</view>
							<view class="active-line"></view>
						</view>
						<view class="item" :class="{'active':form.apply_status==3}" @click="changeStatus(3)">
							<view class="name">不通过</view>
							<view class="active-line"></view>
						</view>
					</view>
				</view>
			</view>
			<view class="body">
				<template v-if="loadingState.default">
					<c-loading :loadingState="loadingState"></c-loading>
				</template>
				<template v-else>
				<template v-if="list.length>0">
					<view class="list-wrap">
						<view class="item" v-for="(item,index) in list" :key="index">
							<view @click="jump(index,8)">
								<view class="name row-2">  
									<text >{{item.username}}发的材料入库申请</text>
									
									<text v-if="item.apply_status==1" class="f-red">审批中</text>
									<text v-if="item.apply_status==2" class="f-red">审批通过</text>
									<text v-if="item.apply_status==3" class="f-red">审批不通过</text> 
									<text v-if="item.apply_status==-1" class="f-red">已撤回</text>
									 
								</view>
								<view class="row-2">
									<text>订单总价格</text> 
									<text >{{item.price}}</text>
								</view>
								<view class="row-2"> 
									<text>申请时间</text>
									<text>{{item.create_time}}</text>
								</view> 
							</view>
							<view v-if="item.apply_status==1" class="btn-wrap">
								<u-button text="同意" type="success" size="small" class="btn" @click="shenpi(1,index)" ></u-button>
								<u-button text="不同意" type="success" size="small" class="btn m-l2" @click="shenpi(2,index)" ></u-button>
							</view>
						</view>
					</view>
					<c-loading :loadingState="loadingState"></c-loading>
					
					 
				</template> 
				
				<c-empty v-else></c-empty>
				</template>
			</view>
		
		</template>
 
		
		
				
		<!-- <c-footer v-if="type=='add'||type=='edit'||type=='list'"> 
			<view v-if="type=='add'" slot="content" class="add-btn" @click="add">提交</view>
			<view v-if="type=='edit'" slot="content" class="add-btn" @click="add">报存</view>
			<navigator v-if="type=='list'" slot="content" url="/package_kucun/address/address?type=add" hover-class="none" class="add-btn">添加地址</navigator>
		</c-footer> -->
	</view>
</template>

<script>
	import {uploadToServe} from '@/common/util.js'
	import {IMG_PATH} from '../../config.js'
	export default {
		data() {
			return {
				id:'',
				isLogin:true, 
				isIphoneX:getApp().globalData.isIphoneX,  
				userInfo:uni.getStorageSync('userInfo'),
				type:'', 
				page:'',
				list:[], 
				show:false,
				form: {
					next_user:'',
					apply_status:'1', 
					keyword:'',
					page:1,
					limit:'10',
					apply_type:1,
					storehouse:'',
					storehouse_name:'',
					payments:'',
					project_statusid:'',
					project_statusname:'',
					fileList1:[]
				},
				loadingState:{
					default:true,
					loading:false,
					completed:false
				},
				storehouse:{
					isShow:false,
					data:[],
					defaultIndex:[]
				},	
				currentindex:'0', 
				tips:'',
				isclick:false,
				project_status:{
					isShow:false,
					data:[[
						{
							value:1,
							name:'未结清'
						},
						{
							value:2,
							name:'已结清'
						},
						{
							value:3,
							name:'部分结清'
						}
					]],
					defaultIndex:[]
				},	
				isStop:true
				
			}
		},
		async onLoad(params) {  
			this.type=params.type; 
			this.page=params.page;
			let title='';
			if(this.type==1){				 
				if(this.page=='list'){ 
					title='我发的审批'; 
					this.getList(); 
				} 
			}
			
			if(this.type==2){
				if(this.page=='list'){ 
					title='需要我审批'; 
					this.getList(); 					
				} 
			}
			
			if(this.type==3){
				if(this.page=='list'){
					this.form.apply_status=2;
					title='需要我发货'; 
					this.getList(); 
				} 
			}
			
			if(this.type==4){
				if(this.page=='list'){
					this.form.apply_status=2;
					title='需要我入库'; 
					this.getList(); 
				} 
			}
			
			if(this.type==5){
				if(this.page=='list'){ 
					title='需要我结清'; 
					this.getList(); 
				} 
			}
			
			if(this.type==6){
				if(this.page=='list'){
					title='抄送给我的'; 
					this.getList(); 
				} 
			}
			
			if(this.type==7){
				if(this.page=='list'){
					title='我发的入库'; 
					this.getList(); 
				} 
			}
			
			if(this.type==8){
				if(this.page=='list'){
					title='需要我审批'; 
					this.getList(); 
				} 
			}
			
			uni.setNavigationBarTitle({
				title:title
			})
			 
		},
		onShow() {
			
		}, 
		onReachBottom(){
			if(this.loadingState.completed){ 
				this.form.page=1;
				return false
			}else{
				this.form.page++;
				this.getList();			
			}	 
		},
		methods: { 
			// 删除图片
			deletePic(event) {
				this.form.fileList1.splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let list_item=this.list[this.currentindex];
				let lists = [].concat(event.file);
				let api_url='/api/product/uploadfile';
				let fileListLen = this.form.fileList1.length
				lists.map((item) => {
					this.form.fileList1.push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				}) 
				for (let i = 0; i < lists.length; i++) {
					// const result = await this.uploadfile(lists[i].url)
					uploadToServe({
						url: api_url,
						filePath: lists[i].url,
						name: 'fileinput',
						formData: {
							apply_type:4,
							apply_id:list_item.apply_id
						}
					}).then((res)=>{ 
						let item = this.form.fileList1[fileListLen]
						this.form.fileList1.splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: `${IMG_PATH}${res.data.file_path}/${res.data.file_name}`,
							name:res.data.file_name
						}))
						fileListLen++ 
					}) 
				}
			},
			
			copy(type,id){ 
				if(type==1){ 
					
				}else if(type==2){
					uni.navigateTo({
						url:'/package_kucun/chuku/chuku?apply_id='+id
					})
				}else if(type==6){
					uni.navigateTo({
						url:'/package_kucun/cangku-huhuan/cangku-huhuan?apply_id='+id
					})
				} 
			},
			jujue(idx){
				let item=this.list[idx];
				let _this=this;
				uni.showModal({
					content:'确定拒绝发货吗？',
					async success(res) {
						if(res.confirm){
							let d_res=await _this.$api.user_api.refuseapply({
								apply_id:item.apply_id
							})  
							if(d_res.data.code==200){
								_this.list=[];
								_this.form.page=1;
								_this.getList();
							}
						}
					}
				}) 
			},
			open(idx) {
				this.show = true;
				this.currentindex=idx;
				let item=this.list[idx];
				if(this.type==2){
					this.mestorehouse(this.currentindex);
				} 				
			},
			recall(id){
				let _this=this;
				uni.showModal({
					content:'确定撤回吗？',
					async success(res) {
						if(res.confirm){
							let d_res=await _this.$api.user_api.merecall({
								apply_id:id
							}) 
							if(d_res.data.code==200){
								_this.list=[];
								_this.form.page=1;
								_this.getList();
							}
						}
					}
				}) 
			},
			close() {
				this.show = false
			},
			changeprojectstatus(e){
				this.form.project_statusid=e.value[0].value;
				this.form.project_statusname=e.value[0].name;
				this.project_status.isShow=false;
			},
			agree(){ 
				let item=this.list[this.currentindex];
				if(!this.isclick&&item.apply_type==2){
					this.$showToast({
						title:this.tips
					})
					return
				} 
				if(this.type==2&&this.form.storehouse==''){
					this.$showToast({
						title:'请选择仓库'
					})
					return
				} 
				this.shenpi(1,this.currentindex)
			},
			
			changestorehouse(e){
				this.form.storehouse_name=e.value[0].val;
				this.form.storehouse=e.value[0].storehouse;
				this.form.next_user=e.value[0].next_user;
				this.storehouse.isShow=false;
				this.storehouse.defaultIndex=e.indexs; 
				this.mecheckcount(this.currentindex);
			},
			
			async mestorehouse(idx){ 
				let item=this.list[idx];
				let res=await this.$api.user_api.mestorehouse({
					apply_id:item.apply_id,
					apply_node:item.apply_node 
				})  
				if(res.data.code==200){
					res.data.data.forEach(item=>{
						item.val=item.sname+' '+item.next_realname
					})
					this.$set(this.storehouse.data,0,res.data.data); 
					// this.form.storehouse_name=res.data.data[0].val;
					// this.form.storehouse=res.data.data[0].storehouse;
					// this.form.next_user=res.data.data[0].next_user;
					if(item.apply_type==2){
						this.mecheckcount(idx);
					}
					
				}
			},
			 
			
			async mecheckcount(idx){
				let item=this.list[idx];
				let res=await this.$api.user_api.mecheckcount({
					apply_id:item.apply_id,
					storehouse:this.form.storehouse 
				}) 
				if(res.data.code==400){
					this.tips=res.data.msg; 
					this.isclick=false;
				}else{
					this.tips=res.data.msg; 
					this.isclick=true;
				}
			},
			
			async shenpi(type,idx){ 
				// type 1 同意  2 不同意
				let item=this.list[idx];  
				let id=item.id;
				let res={}; 
				if(this.isStop){
					this.isStop=false;
					if(type==1){
						if(this.type==2){
							if(item.apply_type==6){ 
								res=await this.$api.user_api.refuseapproval({
									apply_id:item.apply_id,
									storehouseman:this.form.storehouse,
									is_agree:1,
									remark:'同意'
								})  
							}else{
								res=await this.$api.user_api.refuseapproval({
									apply_id:item.apply_id,
									storehouseman:this.form.storehouse,
									is_agree:1,
									remark:'同意'
								})   
								
							}
							
						}
						
						if(this.type==4){
							res=await this.$api.user_api.mesendwx({
								pid:'1',
								apply_type:item.apply_type,
								apply_id:item.apply_id,
								send_storehouseman:item.send_storehouseman,
								last_receive_user:item.last_receive_user, 
							})   
						}
						
						if(this.type==5){  
							if(this.form.project_statusid==''){
								this.$showToast({
									title:'请选择项目状态',
									duration:1000,
								})
								return
							}
							if(this.form.payments==''){
								this.$showToast({
									title:'请输入金额',
									duration:1000,
								})
								return
							}
							if(this.form.fileList1.length==0){
								this.$showToast({
									title:'请上传图片',
									duration:1000,
								})
								return
							}
							let files=[];
							this.form.fileList1.forEach(it=>{
								files.push(it.name)
							}) 
							res=await this.$api.user_api.meupdatestatus({ 
								apply_node:item.apply_node||'',
								apply_id:item.apply_id,
								apply_status:item.apply_status||'',
								last_receive_user:item.last_receive_user||'', 
								project_statusid:this.form.project_statusid,
								payments:this.form.payments,
								files:files.join(',')
							})   
						}
						
						
						if(this.type==8){
							res=await this.$api.user_api.orderpartsagree({
								order_id:id
							})
						}
					}
					
					if(type==2){
						if(this.type==2){  
							res=await this.$api.user_api.medisagree({
								apply_node:item.apply_node,
								apply_id:item.apply_id,
							})  
						}
						
						if(this.type==8){
							res=await this.$api.user_api.orderpartsdisagree({
								order_id:id
							})
							
						}
					}
					 
					if(res.data.code==200){
						this.$showToast({
							icon:'success',
							title:res.data.msg,
							duration:1000,
						})
						this.show=false;
						this.isStop=true;
						this.$store.commit('KUCUN_SHENPI_UPDATE',1);
						 
					}else{
						this.isStop=true;
						this.$showToast({
							icon:'error',
							title:res.data.msg,
							duration:1000,
						})
					}
				}
				
				
			},
			
			changeStatus(val){
				this.form.apply_status=val;
				this.list = [];
				this.form.page=1;
				this.loadingState.default=true;  
				this.loadingState.completed=false;
				this.getList(); 
			},
			
			search() {
				this.list = []; 
				this.form.page=1;
				this.getList(); 
			},
			
			// 清空关键词
			clearKeyword() {
				this.form.keyword = '';
				this.list = [];
				this.form.page=1;
				this.getList(); 
			},
			
			async getList(){
				let {page,limit,keyword,apply_status,apply_type}=this.form;
				let res={};
				let params={ 
					pages:page,
					sizes:limit,
					apply_status,
					search:keyword
				}
				if(this.type==1){
					res=await this.$api.user_api.approvalpending(params);  
				}
			    if(this.type==2){
				    res=await this.$api.user_api.approvalneedapproval(params);  
			    } 
				if(this.type==3){
					params=Object.assign(params, {apply_type:2}) 
				    res=await this.$api.user_api.approvalneedsendwx(params);  
				} 
				if(this.type==4){
					params=Object.assign(params, {apply_type:1}) 
				    res=await this.$api.user_api.approvalneedsendwx(params);  
				} 
				if(this.type==5){
					params=Object.assign(params, {project_status:apply_status}) 
				    res=await this.$api.user_api.approvalneedstatus(params);  
				} 
				if(this.type==6){ 				
				    res=await this.$api.user_api.approvalapplycc(params);  
				}
				if(this.type==7){
				    res=await this.$api.user_api.orderpartspending(params);  
				}
				if(this.type==8){
				    res=await this.$api.user_api.orderpartsneedapproval(params);  
				}  
				if(res.data.code==200){  
					this.loadingState.default=false;
					if(this.type==7||this.type==8){ 
						this.list=this.list.concat(res.data.data.list);	
						if(res.data.data.list.length<limit){
							this.loadingState.completed=true;
						} 
					}else{
						this.list=this.list.concat(res.data.data);	
						if(res.data.data.length<limit){
							this.loadingState.completed=true;
						} 
					}  
				}else{
					this.loadingState.default=false;
				}
			},  
			
			
			async meaddressone(){
				let res=await this.$api.user_api.meaddressone({
					id:this.id
				})     
				if(res.data.code==200){ 
					this.form.user_name=res.data.data.userrealname;
					this.form.phone=res.data.data.phone;
					this.form.address=res.data.data.address;
					this.form.isdefault=res.data.data.default==1?true:false;					 
				}
			},
			 
			
			async add(){
				let {user_name,isdefault,address,phone}=this.form;
				 
				if(user_name==''){
					this.$showToast({
						title:'请输入用户名',
						duration:1000,
					})
					return
				}
				if(phone==''){
					this.$showToast({
						title:'请输入收货人手机',
						duration:1000,
					})
					return
				}
				if(address==''){
					this.$showToast({
						title:'请输入详细地址',
						duration:1000,
					})
					return
				}
				let res=await this.$api.user_api.meaddcustinfo({
					id:this.id,
					user_name,
					address,
					phone,
					default:isdefault?'on':'off', 
				}) 
				if(res.data.code==200){
					this.$showToast({
						icon:'success',
						title:res.data.msg,
						duration:1000,
					})
					this.$store.commit('KUCUN_ADDRESS_UPDATE',1);
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},300)						
				}
				 
			},
			
			async jump(idx,type){ 
				let item=this.list[idx];
				let apply_id=item.apply_id||item.id; 
				let url=''; 
				if(this.type==7||this.type==8){
					url=`/package_kucun/msg-detail/msg-detail?order_id=${apply_id}&type=${type}`
				}else{
					if(item.notice_id){
						url=`/package_kucun/msg-detail/msg-detail?notice_id=${apply_id}&apply_id=${apply_id}&type=${type}`
					}else{
						url=`/package_kucun/msg-detail/msg-detail?form_status=${this.form.apply_status}&apply_id=${apply_id}&type=${type}`
					}
				}
				
				uni.navigateTo({
					url:url
				})
			},
			
			sendproduct(idx){
				let item=this.list[idx];
				let apply_id=item.apply_id||item.id;
				let apply_type=item.apply_type;
				uni.navigateTo({
					url:`/package_kucun/send-product/send-product?form_status=${this.form.apply_status}&apply_type=${apply_type}&apply_id=${apply_id}`
				})
			}
			 
		},
		computed:{
			list_update(){
				return this.$store.state.kucun_address_list;
			},
			
			shenpi_update(){ 
				return this.$store.state.kucun_shenpi_update;
			}
		},
		watch:{
			list_update(newer,older){ 
				if(newer!=older){
					this.list=[]; 
					this.loadingState={
						default:true,
						loading:false,
						completed:false
					};
					this.getList();
				} 
			},
			
			shenpi_update(newer,older){
				if(newer!=older){
					this.list=[]; 
					this.loadingState={
						default:true,
						loading:false,
						completed:false
					};
					this.getList();
				} 
			} 
			
		}
	}
</script>

<style lang="less" >
	.storehouse-pupup{
		padding: 30rpx;
		width: 500rpx;
	}
	.form-wrap{
		padding:0 20rpx; 
		.row-2{
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	}
	.slot-content{
		.hd{
			padding: 30rpx 0 10rpx;
			font-size: 30rpx;
		}
	}
	.popup-form-wrap{
		padding:20rpx;
		border-radius: 15rpx;		 
	}
	 
	.add-btn{
		height: 36px;
		line-height: 36px;
		width: 96%;
		margin: 5px auto;
		background: #1cab1b;
		border-radius: 8rpx;
		color: #fff;
		font-size: 30rpx;
		text-align: center;
	}  
	.list-wrap{
		padding:20rpx 0;
		.item{ 
			padding:20rpx; 
			margin-bottom: 20rpx;
			background: #fff; 
			color: #999;
			font-size: 30rpx;
			.name{
				padding: 20rpx 0;
				color:#333;
			}
			.row-2{
				display: flex;
				justify-content: space-between;
				margin-bottom: 10rpx;
			}
			.row-1{				 
				margin-bottom: 10rpx;
				color: #333;
				font-size: 30rpx;
			}
			.btn-wrap{
				display: flex;
				justify-content: flex-end;
				align-items: center;
				padding:20rpx 0 0; 
				border-top: 1rpx solid #e5e5e5;
				font-size: 30rpx;
				.btn{
					padding: 10rpx 20rpx;
					margin-left: 20rpx;
					background: #1cab1b;
					border-radius: 8rpx;
					color: #fff;
				}
			}
			.copy-btn{
				position: relative;
				z-index: 1;
				width: 90rpx;
				font-size: 30rpx;
			}
			 
		}
	}
</style>
